import router from '@/router'
import { useLoginUserStore } from '@/stores/useLoginUserStore.ts'
import { message } from 'ant-design-vue'


router.beforeEach((to, from, next) => {
  const loginUserStore = useLoginUserStore();
  const loginUser = loginUserStore.loginUser;
  const toUrl = to.fullPath;
  if (toUrl.startsWith('/admin')) {
    if (!loginUser || loginUser.userRole !==`admin`) {
      message.error("没有权限");
      next(`/user/login?redirect=${to.fullPath}`);
    }
  }
  next();
})
